import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class TopNavigator extends StatelessWidget {
  final List navigatorList;

  TopNavigator({Key key, this.navigatorList}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    /*后端返回数据过长  截取前10条数据*/
    if (this.navigatorList.length > 10) {
      this.navigatorList.removeRange(10, this.navigatorList.length);
    }

    return Container(
      alignment: Alignment.center,
      height: ScreenUtil().setHeight(330),
      child: Container(
        // height: ScreenUtil().setHeight(320),
        child: GridView.count(
          crossAxisCount: 5,
          //解决  ListView/SingleChildScrollView嵌套GridView滑动冲突
          physics: new NeverScrollableScrollPhysics(),
          padding: EdgeInsets.fromLTRB(0, 12.0, 0, 12.0),
          children: navigatorList.map((item) {
            return _gridViewItemUi(context, item);
          }).toList(),
        ),
      ),
    );
  }

  Widget _gridViewItemUi(BuildContext context, item) {
    return InkWell(
      onTap: () {},
      child: Column(
        //设置 横向居中
        crossAxisAlignment: CrossAxisAlignment.center,
        //设置纵向居中
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Image.network(
            item['image'],
            width: ScreenUtil().setWidth(80),
            height: ScreenUtil().setWidth(80),
          ),
          Padding(
            padding: EdgeInsets.fromLTRB(0, 4.0, 0, 0),
            child: Text(
              item['mallCategoryName'],
              style: TextStyle(fontSize: 12.0, color: Colors.black),
            ),
          )
        ],
      ),
    );
  }
}
